#include "stdafx.h"
#include <gtest/gtest.h>
#include <boost/thread.hpp>
#include <utility/utility.h>
#include "TaskManager.h"
using namespace Zen::utility;

#if 0
critical_section cs;
TaskManager mgr;

void fun1()
{
	while (1)
	{mgr.add(L"127.0.0.1"); Sleep(100);}
}


void fun2()
{
	while (1)
	{mgr.remove(L"127.0.0.1");Sleep(110);}
}


void fun3()
{
	while (1)
	{printf("%s\n", mgr.has_ip(L"127.0.0.1") ? "true" : "false");Sleep(100);}
}




void func3()
{
	//locker _;
	cs.lock();
	printf("%s\n", __FUNCDNAME__);
	Sleep(3000);
	cs.unlock();
}

TEST(test, MyCriticalSectionLocker)
{
	//InitializeCriticalSection(&MyCriticalSectionLocker::cs);
	//cs.lock();
	//cs.lock();

	boost::thread_group tg;
	//tg.create_thread(func1);
	//tg.create_thread(func2);
	//cs.lock();
	//cs.lock();
// 	cs.lock();
// 	cs.unlock();
	tg.create_thread(fun1);
	tg.create_thread(fun2);
	tg.create_thread(fun3);
	tg.join_all();
	Sleep(10000);

	//DeleteCriticalSection(&MyCriticalSectionLocker::cs);

}

#endif